package org.gwtEss.table;

import org.gwtEss.other.ChkBox;

import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HasHorizontalAlignment.HorizontalAlignmentConstant;

public abstract class HeaderDetailWidget<VO> extends Composite{
	
//	private OnDemandTable<ColWidget> tab;
	private TabAdapter<ColWidget> tab;
	private Cols<VO> parentCols; 
	private boolean rendered = false; 
	public HeaderDetailWidget(Cols<VO> cols) {
		this.parentCols = cols; 
		init();
		initWidget(tab);
	}
//	public abstract void setVisible(ColWidget col, Boolean value);
//	public abstract boolean isVisible(ColWidget col);
	abstract boolean resetColVisibility(ColWidget data);
	
	private void init(){
		Cols<ColWidget> colDef = new Cols<ColWidget>();
		
		colDef.add(new SmartUserManagedColWidget<ColWidget, ChkBox>("select", 20){

			public ChkBox createColWidgetInstance() {
				return new ChkBox();
			}

			public boolean resetData(ChkBox w, ColWidget data) {
//				setVisible(data, w.getValue());
				data.setVisible(w.getValue());
				resetColVisibility(data);
				return true;
			}


			public void resetWidget(ColWidget data, ChkBox w) {
//				isVisible(data);
				w.setText(data.getColName());
				w.setValue(data.isVisible());
			}

			public HorizontalAlignmentConstant alignment() {
				return HasHorizontalAlignment.ALIGN_LEFT;
			}
			
		});
		
/*		colDef.add(new ReadOnlyTextColWidget<ColWidget>("Column", 150){

			public TextDesc createDisplayText(ColWidget data) {
				return new TextDesc(false, data.getColName());
			}

			public HorizontalAlignmentConstant alignment() {
				return HasHorizontalAlignment.ALIGN_LEFT;
			}

		});*/
		
/*		tab = new OnDemandTable<ColWidget>(colDef, 100, 100, parentCols.size()){

			@Override
			public void fetchRowData(
					ArrayList<Integer> rowNumList,
					org.gwtEss.table.OnDemandTable.FetchCompleteCallBack<ColWidget> fetchComplete) {
				fetchComplete.onFetchComplete(parentCols);
			}};
		*/
			/*Tab<ColWidget> */
		tab = new TabAdapter<ColWidget>(/*parentCols.size(), */colDef);
			
	}
	public void render(){
		if (!rendered){
			int row = 0;
//			int[] colsWidth = {20, 150};
			tab.resizeCols();
			for (ColWidget col: parentCols)
				tab.render(row++, col);
		}
//			tab.render(parentCols.size());
	}


}
	